<template>
  <div class="container">
    <el-dialog
      title="预览文章"
      :visible="isShow"
      width="800px"
      @close="closeDialog"
    >
      <div class="preview">
        <!-- 标题 -->
        <h2 class="title">{{ detail.title }}</h2>
        <p class="time">
          {{ formatDate(detail.createTime) }} <span style="margin-left:10px"> {{ detail.username }}</span>
          <i style="margin-left:10px" class="el-icon-view"></i> {{ detail.visits }}
        </p>
        <div class="main" v-html="detail.articleBody"></div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { detail } from '@/api/hmmm/articles.js'
export default {
  data () {
    return {
      detail: {}
    }
  },
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  created () {

  },
  methods: {
    // 时间格式化
    formatDate (value, str = 'YYYY-MM-DD HH:mm:ss') {
      return dayjs(value).format(str)
    },

    // 获取数据
    async getData (data) {
      const { data: res } = await detail(data)
      console.log(res)
      console.log(data)
      this.detail = res
      this.detail.username = data.username
    },
    // 弹框
    // 关闭弹框
    closeDialog () {
      this.$emit('update:isShow', false)
    },
    // 弹框确认
    dialogOk () {
    }
  }
}
</script>

<style scoped lang='scss'>
.main {
  background-color: #eee;
  padding: 20px;
  border-top: 1px dashed #ccc;
}
.time {
  margin-left: 20px;
}
.title {
  margin-left: 10px;
}
</style>
